#pragma once

#include <qwidget.h>
#include "qcustomplot.h"
#include <QTimer>

#include "datastruct.h"
// #include "WidgetEx.h"
// #include "DataDefine.h"
// #include "IntToString.h"
#include "TreeDirectoryWidget.h"

class WdtCustomChart : public QWidget
{
	Q_OBJECT

public:
	WdtCustomChart(QWidget* parent=nullptr);
	~WdtCustomChart();

	void init();

private:
	void initTreeData(QMap<int, DevStationData* >& devMap);
	void initPlot();
	void UpdateGraphPlot(QString id,bool check);
	//曲线号
	void UpdateGraphPlotData(QString id, int key, double value);
	void UpdateGraphPlotData(QString id,int key);

	//多段y轴、共用x轴坐标系
	//根据勾选的通道号创建坐标系
	QCPAxisRect* CreateQCPAxisRect(QString channel);
	//删除坐标系
	void RemoveQCPAxisRect(QString channel);
	//x轴y轴同步
	void ConnectAllAxisx(bool on);
	//更新设置共用一个x轴
	void UpdateSettingCommonXaXisx();

public slots:
	void SlotItemChange(QString id,bool check);
	void SlotDataTimeOut();

private:

	TreeDirectoryWidget* m_treeWidget = nullptr;
	QCustomPlot* m_plot;
	QCPRange m_originXRange;
	QMap<int, DevStationData* > m_devMap;
	QMap<QString, bool> m_select_checkbox;
	QMap<QString,int> m_ploy_index_channel;	//通道号 绑定 曲线号

	//动态增加删除通道所对应的曲线图
	QMap<int, QCPAxisRect*> m_channel_axises;	//每一个通道相对应的纵坐标
	QMap<int, QCPGraph*> m_channel_plots;		//每一个通道所对应的曲线
	QTimer* m_data_timer;
	//y轴动态变化值
	int max = 50;	
	int min = 0;
};
